package com.huluobo.apps

import com.huluobo.lib_base.BaseViewModel
import com.huluobo.lib_base.Res
import com.huluobo.lib_base.UIIntent
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

/**
 *  Created by LC on 2025/4/23.
 *  在线应用的ViewModel,主要功能是处理意图,根据不同的意图来产生不同的网络请求
 *  如果是数据库,就直接通过数据库获取数据
 */
@HiltViewModel
class AppsViewModel @Inject constructor(private val appsRepo: AppsRepo) : BaseViewModel<AppsIntent>() {
    override fun handleIntent(it: UIIntent) {
        when (it) {
            is AppsIntent.GetApps -> {
                httpRequest(appsRepo.getApps() as Flow<Res<Any>>)
            }

            is AppsIntent.DownloadApk -> {
                download(it.url, it.file)
            }
        }
    }
}